- var colClass = "col-lg-6 px-2";
if (exchangeRates || networkVolume)
	- colClass = "col-lg-4 px-2";

- var utxoCalculatingDesc = "At startup the app pulls a summary of the UTXO set. Until this summary is retrieved this data can't be displayed. Wait for the summary request to your node to return, then refresh this page.";


- let halvingSoon = false;
- let halvingVerySoon = false;
- let halvingProgressPercent = 0;

if (nextHalvingData)
	- halvingProgressPercent = new Decimal(100).minus(new Decimal(nextHalvingData.blocksUntilNextHalving).dividedBy(nextHalvingData.halvingBlockInterval).times(100));

	if (halvingProgressPercent > 65)
		- halvingSoon = true;

	if (halvingProgressPercent > 98)
		-halvingVerySoon = true;


if (halvingVerySoon)
	#index-halving-countdown-wrapper
		.d-flex.justify-content-start
			.text-success
				+sectionTitle("Halving Countdown 👀")

			.ms-2
				span.spinner-border.spinner-border-sm
		
		
		.mb-section
			.card.mb-section.shadow-sm.border-2.border-success
				.card-body
					div#index-halving-countdown
						.text-center.text-reset
							.mt-2
							.spinner-border.spinner-border-sm

if (exchangeRates)
	+contentSection("Market")
		- var colCount = 3 + (networkVolume ? 1 : 0) + (goldExchangeRates ? 1 : 0);
		+summaryRow(colCount)
			- var tzDiff = -parseFloat(browserTzOffset);
			if (userTzOffset != "unset")
				- tzDiff = parseFloat(userTzOffset);

			- var tzMoment = moment.utc(global.exchangeRatesUpdateTime).add(tzDiff, "hours");
			- var timeText = tzMoment.format("h:mma");

			+summaryItem("Exchange Rate", `Source: ${new URL(coinConfig.exchangeRateData.jsonUrl).hostname}<br/>Last Updated: ${timeText} (${new Decimal(new Date().getTime() - global.exchangeRatesUpdateTime.getTime()).dividedBy(1000).dividedBy(60).toDP(0)} min ago)`)
				- var formatData = utils.formatExchangedCurrency(1.0, userSettings.localCurrency, 0);

				span.text-success
					span.me-1 #{formatData.symbol}
					| #{formatData.val}

			+summaryItem("Sats Rate")
				- var satsRateData = utils.satoshisPerUnitOfLocalCurrency(userSettings.localCurrency);
				span #{satsRateData.amt}
					small  #{satsRateData.unit}

			+summaryItem("Market Cap")
				- var supply = utils.estimatedSupply(getblockchaininfo.blocks);
				- var mcapData = utils.formatLargeNumber(parseFloat(supply) * global.exchangeRates[userSettings.localCurrency], 3);

				span.me-1 #{global.currencyTypes[userSettings.localCurrency].symbol}
				
				span #{mcapData[0]}
				if (mcapData[1].textDesc)
					span.ms-1 #{mcapData[1].textDesc}
				else
					span  x 10
					sup #{mcapData[1].exponent}

				// ["154.9",{"val":1000000000,"name":"giga","abbreviation":"G","exponent":"9"}]

			if (global.goldExchangeRates && global.goldExchangeRates["usd"] && global.exchangeRates && global.exchangeRates["usd"])
				// usd is the only bridge for our data sources
				+summaryItem("Gold Rate", `Source: ${new URL(coinConfig.goldExchangeRateData.jsonUrl).hostname}`)
					- var formatData = utils.formatExchangedCurrency(1.0, "au");

					span.text-warning #{formatData.val}
					small.ms-1.text-muted #{formatData.unit}

			if (networkVolume)
				+summaryItem("24hr Volume", `Total output of all transactions over the last 24hrs (blocks: [#${networkVolume.d1.endBlock.toLocaleString()} - #${networkVolume.d1.startBlock.toLocaleString()}]).`)
					- var currencyValue = parseInt(networkVolume.d1.amt);
					- var currencyValueDecimals = 0;

					if (userSettings.displayCurrency == "btc")
						+valueDisplaySpecial(networkVolume.d1.amt, 0)

					else
						+valueDisplay(networkVolume.d1.amt)

					

.clearfix
	.float-start
		+sectionTitle("Network Summary")
	.float-end
		if (userSettings.homepageShowTechDetails == "true")
			a.me-2(href="./changeSetting?name=homepageShowTechDetails&value=false", title="Hide technical network details", data-bs-toggle="tooltip", data-bs-placement="bottom")
				i.bi-hdd-stack.text-muted

		else
			a.me-2(href="./changeSetting?name=homepageShowTechDetails&value=true", title="Show technical network details", data-bs-toggle="tooltip", data-bs-placement="bottom")
				i.bi-hdd-stack.text-muted


+contentSection
	+summaryRow(2 + (halvingSoon ? 1 : 0) + (hashrate7d ? 1 : 0) + (chainTxStats && chainTxStats[7 * targetBlocksPerDay] ? 1 : 0) + (difficultyAdjustmentData ? 1 : 0))
		if (hashrate7d)
			+summaryItem("7d Hashrate", "The average hashrate of the global mining network over the last 7 days. A comparison to the 30-day average is included to help gauge the rate of change.")
				- var hashrate7dayData = utils.formatLargeNumber(hashrate7d, 1);

				span.me-1 #{hashrate7dayData[0]}
				span.small.text-muted.border-dotted(title=`${hashrate7dayData[1].abbreviation}H = ${hashrate7dayData[1].name}-hash (x10^${hashrate7dayData[1].exponent})` data-bs-toggle='tooltip') #{hashrate7dayData[1].abbreviation}H/s

				if (hashrate30d)
					- var ratio = hashrate7d / hashrate30d;

					span.text-tiny.text-muted.ms-2
						| (
						span.border-dotted(title='7d hashrate vs 30d hashrate.' data-bs-toggle='tooltip')
							if (ratio > 1)
								- var ratioPercent = new Decimal(ratio).times(100).minus(100);
								span.text-success +#{ratioPercent.toDP(2)}%

							else
								- var ratioPercent = new Decimal(100).minus(new Decimal(ratio).times(100));
								span.text-danger -#{ratioPercent.toDP(2)}%

						| )

		if (halvingSoon)
			if (false)
				pre #{JSON.stringify(nextHalvingData)}
			
			+summaryItem("Next Halving", "Details about when the next block subsidy halving will occur", null, null, "icon:bi-square-half", "./next-halving", "View next halving details")

				span.border-dotted(title=`${nextHalvingData.blocksUntilNextHalving.toLocaleString()} blocks left, ${halvingProgressPercent.toDP(2)}% complete`, data-bs-toggle="tooltip")
					if (nextHalvingData.blocksUntilNextHalving > 10000)
						- let halvingBlocksData = utils.formatLargeNumber(nextHalvingData.blocksUntilNextHalving)
						| #{parseInt(halvingBlocksData[0])}#{halvingBlocksData[1].abbreviation}
							
					else
						| #{nextHalvingData.blocksUntilNextHalving.toLocaleString()}


				- var utcMoment = moment.utc(nextHalvingData.nextHalvingDate);
				- var titleStr = `${utcMoment.format("Y-MM-DD, HH:mm:ss")} utc`;
				- let halvingDt = moment.duration(moment.utc(nextHalvingData.nextHalvingDate).diff(moment.utc(new Date())));
				
				i.text-tiny.bi-box.ms-2
				small.text-muted.ms-2
					| (
					span.border-dotted(title=`${utils.summarizeDuration(halvingDt)} (${new Decimal(halvingDt.asDays()).toDP(3)} d) <br/> ${titleStr}`, data-bs-toggle="tooltip", data-bs-html="true")
						+timeAgo(nextHalvingData.nextHalvingDate.getTime() / 1000, {hideHoverText:true, decimalPlaces:3})
					| )

				.progress.mt-1.mx-lg-6.me-6(style="height: 5px;", role="progressbar", aria-label="Difficulty adjustment progress", aria-valuenow=halvingProgressPercent.toDP(0), aria-valuemin="0" aria-valuemax="100")
						.progress-bar(style=`width: ${halvingProgressPercent.toDP(0)}%`)

		+summaryItem("Difficulty", null, null, null, "icon:bi-clock-history", "./difficulty-history", "View difficulty history")
			- var difficultyData = utils.formatLargeNumber(getblockchaininfo.difficulty, 3);
			
			if (getblockchaininfo.difficulty > 1000)
				span.border-dotted(title=parseFloat(getblockchaininfo.difficulty).toLocaleString(), data-bs-toggle="tooltip")
					span #{difficultyData[0]}
					span  x 10
					sup #{difficultyData[1].exponent}

			else
				span #{new Decimal(getblockchaininfo.difficulty).toDP(3)}

			if (global.athDifficulty)
				span.text-tiny.text-muted.ms-2
					| (

					- var diffX = getblockchaininfo.difficulty;
					if (global.athDifficulty == diffX)
						span.border-dotted(title='The current difficulty is an All-Time High!' data-bs-toggle='tooltip')
							span.text-success ATH
					else
						- var diffDrop = new Decimal(global.athDifficulty).minus(diffX).dividedBy(global.athDifficulty).times(100).toDP(2);

						span.border-dotted(title=`The current difficulty is ${diffDrop}% lower than the All-Time High.` data-bs-toggle='tooltip')
							span.text-danger -#{diffDrop}%

					| )
				


		if (chainTxStats && chainTxStats[7 * targetBlocksPerDay])
			+summaryItem("7d Transactions", "The total number of transactions that have been confirmed in the blockchain over the last 7 days.")
				| #{chainTxStats[7 * targetBlocksPerDay].window_tx_count.toLocaleString()}

		if (difficultyAdjustmentData)
			- let progressPercent = new Decimal(difficultyAdjustmentData.calculationBlockCount).dividedBy(difficultyAdjustmentData.calculationBlockCount + difficultyAdjustmentData.blocksLeft).times(100);

			- var desc = `Estimate for the difficulty adjustment that will occur in ${difficultyAdjustmentData.blocksLeft.toLocaleString()} block${difficultyAdjustmentData.blocksLeft == 1 ? "" : "s"} (${difficultyAdjustmentData.timeLeftStr}). This is calculated using the average block time during the current difficulty epoch (currently, the last ${difficultyAdjustmentData.calculationBlockCount.toLocaleString()} block${difficultyAdjustmentData.calculationBlockCount == 1 ? "" : "s"}). Note: This estimate becomes more reliable as the difficulty epoch nears its end.`;
			
			if (false)
				pre
					code.json #{JSON.stringify(difficultyAdjustmentData, null, 4)}

			+summaryItem("Difficulty Δ", difficultyAdjustmentData.estimateAvailable ? desc : null)
				if (difficultyAdjustmentData.estimateAvailable)
					span(class=(difficultyAdjustmentData.delta >= 0 ? "text-success" : "text-danger"))
						if (difficultyAdjustmentData.sign == "+")
							| +

						| #{difficultyAdjustmentData.delta.toDP(2)}
						small.ms-1 %

					span.text-tiny.text-muted.ms-2
						| (
						span.border-dotted(title=`${difficultyAdjustmentData.blocksLeft.toLocaleString()} block${difficultyAdjustmentData.blocksLeft == 1 ? "" : "s"} / ${progressPercent.toDP(1)}% done`, data-bs-toggle="tooltip") #{difficultyAdjustmentData.timeLeftStr}
						| )

					
					.progress.mt-1.mx-lg-6.me-6(style="height: 5px;", role="progressbar", aria-label="Difficulty adjustment progress", aria-valuenow=progressPercent.toDP(0), aria-valuemin="0" aria-valuemax="100")
						.progress-bar(style=`width: ${progressPercent.toDP(0)}%`)

				else
					small.border-dotted.text-muted(title="Estimate pending...<br/>A new difficulty epoch just started. Difficulty adjustment estimates made with too little data can be very unreliable, so are not calculated.", data-bs-toggle="tooltip", data-bs-html="true")
						i.bi-hourglass-split

		+summaryItem("Coins", utxoSetSummary ? null : (config.slowDeviceMode ? `Because this app is configured to conserve resources (SLOW_DEVICE_MODE=true), this value is estimated, using a checkpoint.` : `This value is estimated, using a checkpoint.`))
			- var maxSupply = coinConfig.maxSupplyByNetwork[activeBlockchain];

			if (utxoSetSummary)
				span #{parseFloat(utxoSetSummary.total_amount).toLocaleString()}
				span.text-tiny.ms-2.text-muted
					| (
					span.border-dotted(title=`${new Decimal(utxoSetSummary.total_amount).dividedBy(maxSupply).times(100).toDP(5)}% have been mined into circulation`, data-bs-toggle="tooltip") #{new Decimal(utxoSetSummary.total_amount).dividedBy(maxSupply).times(100).toDP(2, Decimal.ROUND_DOWN)}%
					| )

			else
				- var estimatedSupply = utils.estimatedSupply(getblockchaininfo.blocks);

				span #{parseInt(estimatedSupply).toLocaleString()}
				span.text-tiny.ms-2.text-muted
					| (
					span.border-dotted(title=`${estimatedSupply.dividedBy(maxSupply).times(100).toDP(4)}% have been mined into circulation`, data-bs-toggle="tooltip") #{estimatedSupply.dividedBy(maxSupply).times(100).toDP(1)}%
					| )

		

	hr.mt-3.mb-3

	- var smartFeeEstimateBlocks = [];
	- var smartFeeEstimateStrings = [];
	- var smartFeeEstimateTimes = [];
	if (smartFeeEstimates)
		if (smartFeeEstimates[1])
			- smartFeeEstimateBlocks.push(1);
			- smartFeeEstimateStrings.push(smartFeeEstimates[1]);
			- smartFeeEstimateTimes.push('asap');
		if (smartFeeEstimates[6])
			- smartFeeEstimateBlocks.push(6);
			- smartFeeEstimateStrings.push(smartFeeEstimates[6]);
			- smartFeeEstimateTimes.push('hr');
		if (smartFeeEstimates[144])
			- smartFeeEstimateBlocks.push(144);
			- smartFeeEstimateStrings.push(smartFeeEstimates[144]);
			- smartFeeEstimateTimes.push('day');

	+summaryRow((mempoolInfo == undefined ? 0 : 1) + (smartFeeEstimateStrings.length > 0 ? 1 : 0) + ((mempoolInfo && global.activeBlockchain != "signet") ? 1 : 0))
		if (mempoolInfo)
			- const thresholds_txCount = {warning: 7000, danger: 11000}
			- const colorClass_txCount = (mempoolInfo.size > thresholds_txCount.danger) ? "text-danger" : (mempoolInfo.size > thresholds_txCount.warning ? "text-warning" : "text-success")
			- const blockCount = new Decimal(mempoolInfo.bytes).dividedBy(coinConfig.maxBlockSize)
			- const thresholds_blockCount = {warning: 10, danger: 20}
			- const colorClass_blockCount = (blockCount > thresholds_blockCount.danger) ? "text-danger" : (blockCount > thresholds_blockCount.warning ? "text-warning" : "text-success");
			- const thresholds_totalFees = {warning: 1, danger: 5}
			- const colorClass_totalFees = (mempoolInfo.total_fee > thresholds_totalFees.danger) ? "text-danger" : (mempoolInfo.total_fee > thresholds_totalFees.warning ? "text-warning" : "text-success");
			
			+summaryItem("Mempool", "The number of unconfirmed transactions in your node's mempool, and the number of blocks needed to confirm those transactions", null, null, "icon:bi-hourglass-split", "./mempool-summary", "View mempool summary details")
				
				span.border-dotted(title=`<b># Unconfirmed Transactions</b><br/><span class='text-success'>Low (N ≤ ${thresholds_txCount.warning.toLocaleString()})</span><br/><span class='text-warning'>High (${thresholds_txCount.warning.toLocaleString()} < N ≤ ${thresholds_txCount.danger.toLocaleString()})</span><br/><span class='text-danger'>Very High (N > ${thresholds_txCount.danger.toLocaleString()})</span>`, data-bs-toggle="tooltip", data-bs-html="true")
					span(class=colorClass_txCount) #{mempoolInfo.size.toLocaleString()}
					span.text-tiny.text-muted.ms-1 tx

				span.mx-2.text-muted /

				span.small
					span.border-dotted(title=`<b># Blocks to clear this node's mempool</b><br/><span class='text-success'>Low (N ≤ ${thresholds_blockCount.warning.toLocaleString()})</span><br/><span class='text-warning'>High (${thresholds_blockCount.warning.toLocaleString()} < N ≤ ${thresholds_blockCount.danger.toLocaleString()})</span><br/><span class='text-danger'>Very High (N > ${thresholds_blockCount.danger.toLocaleString()})</span>`, data-bs-toggle="tooltip", data-bs-html="true")
						span(class=colorClass_blockCount) #{blockCount.toDP(2)}
						span.text-tiny.text-muted.ms-1
							i.bi-box

				span.mx-2.text-muted /

				span.small
					-
						// Code inspired from shared-mixins.pug and adapted for inclusion in a tooltip
						const formatFees = (inputVal) => {
							const displayCurrency = userSettings.displayCurrency == "local" ? userSettings.localCurrency : userSettings.displayCurrency;
							const parts = utils.formatCurrencyAmount(inputVal, displayCurrency)
							const currencyType = currencyTypes[parts.currencyUnit.toLowerCase()]
							let val = parts.val
							if (currencyType.type == "exchanged") {
								// Remove any decimals
								val = val.split('.')[0]
								// Currency symbol followed by amount with a non-breaking space in-between
								// so that the two elements remain on the same line
								return `${currencyType.symbol}&nbsp;${val}`
							}
							if (parts.currencyUnit == "sat") {
								// Add K, M, G, ... suffix to amount
								const largeNumberData = utils.formatLargeNumberSignificant(parts.intVal, 3);
								val = `${largeNumberData[0]}${largeNumberData[1].abbreviation}`
							}
							// Amount followed by minimized currency name (BTC or sat) with a non-breaking space in-between
							return `${val}&nbsp;<span class='text-tiny'>${currencyType.name}</span>`
						}
					- const warningFees = formatFees(thresholds_totalFees.warning)
					- const dangerFees = formatFees(thresholds_totalFees.danger)
					span.border-dotted(title=`<b>Unconfirmed Transactions' total fees</b><br/><span class='text-success'>Low (N ≤ ${warningFees})</span><br/><span class='text-warning'>High (${warningFees} < N ≤ ${dangerFees})</span><br/><span class='text-danger'>Very High (N > ${dangerFees})</span>`, data-bs-toggle="tooltip", data-bs-html="true") &Sigma;
					// Don't embed this span inside previous one to avoid collision of their tooltips
					span.ms-1(class=colorClass_totalFees)
						+valueDisplay(mempoolInfo.total_fee, {hideLessSignificantDigits:true})

		if (mempoolInfo && global.activeBlockchain != "signet")
			+summaryRow
				+summaryItem("Next Block", "A prediction for what transactions will be included in the next block, yet to be mined. Built from \"getblocktemplate\".", null, null, "icon:bi-minecart-loaded", "./next-block", "View next block details")

					#index-next-block
						.text-center.text-reset.pb-4
							.mt-2
							.spinner-border.spinner-border-sm


		if (false)
			+summaryItem("Next Block (est.)")
				| #{new Decimal(nextBlockMinFeeRate).toDP(0)}
				a(href=`./tx/${nextBlockMinFeeTxid}`)
					i.bi-circle
				| - #{new Decimal(nextBlockMaxFeeRate).toDP(0)}
				a(href=`./tx/${nextBlockMaxFeeTxid}`)
					i.bi-circle
				small.ms-2.text-muted sat/vB

		if (smartFeeEstimateStrings.length > 0)
			+summaryItem(`Smart Fees`, `The recommended fee rate to target confirmation in ${smartFeeEstimateBlocks.join(", ")} blocks`, "sat/vB")
				each x, xIndex in smartFeeEstimateStrings
					if (xIndex > 0)
						span.mx-2.text-muted /

					| #{x}
					span.text-tiny.text-muted.ms-1 (#{smartFeeEstimateTimes[xIndex]})

		

	if (userSettings.homepageShowTechDetails == "true")
		hr.mt-3.mb-3

		+summaryRow(1 + (getblockchaininfo.size_on_disk ? 1 : 0) + (utxoSetSummary || utxoSetSummaryPending ? 1 : 0))
			if (getblockchaininfo.size_on_disk)
				+summaryItem("Disk Usage")
					- var sizeData = utils.formatLargeNumber(getblockchaininfo.size_on_disk, 1);
					| #{sizeData[0]} #{sizeData[1].abbreviation}B

			+summaryItem("Total Hashes", "Estimate of the total work necessary to produce the blockchain, measured in 'hashes'.")
				- var chainworkData = utils.formatLargeNumber(parseInt("0x" + getblockchaininfo.chainwork), 2);
				span #{chainworkData[0]}
				small.px-2.px-lg-0.px-xl-2 x
				span 10
				sup #{chainworkData[1].exponent}


			if (utxoSetSummary || utxoSetSummaryPending)
				+summaryItem("UTXOs", "The total number of unspent transaction outputs (spendable coin units).")
					if (utxoSetSummary)
						- var utxoCount = utils.formatLargeNumber(utxoSetSummary.txouts, 2);
						//| #{utxoCount[0]} #{utxoCount[1].abbreviation}
						| #{utxoSetSummary.txouts.toLocaleString()}
					else
						small.text-muted.border-dotted(title=utxoCalculatingDesc, data-bs-toggle="tooltip") calculating...


